/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef _M_GUI_H_
#define _M_GUI_H_

#include "signal.h"
#include "common.h"
#include "inputsystem.h"
#include "ceguiresourcemanager.h"
#include "types.h"

#include "appheaders.h"


namespace Engine
{
	/**
	*   Interface for gui system.
	*/
	class GUI
	{
	public:

		GUI();
		~GUI();

		void Init(LPDIRECT3DDEVICE9 device,RenderWindowPtr window, InputSystemPtr input);

		void MouseMove(REAL x, REAL y);
		void MouseDown(InputSystem::MouseButton but);
		void MouseUp(InputSystem::MouseButton but);
		void MouseWheel(REAL val);
		void KeyDown(unsigned int key);
		void KeyUp(unsigned int key);
		void CharPressed(unsigned short key);

		void Render();
		void StartReset();
		void FinishReset();

		void ShowGameMenu();
		bool ExitGame();

		Signal<> StartGameSignal;
		Signal<> ExitGameSignal;
		Signal<> ResumeGameSignal;
		Signal<> QuitSignal;

		//GUI events
		bool OnStartClick(const CEGUI::EventArgs& pEventArgs);
		bool OnOptionsClick(const CEGUI::EventArgs& pEventArgs);
		bool OnQuitClick(const CEGUI::EventArgs& pEventArgs);
		bool OnCreditsClick(const CEGUI::EventArgs& pEventArgs);
		bool OnOptionsOkClick(const CEGUI::EventArgs& pEventArgs);
		bool OnOptionsNoClick(const CEGUI::EventArgs& pEventArgs);
		bool OnCreditsClose(const CEGUI::EventArgs& pEventArgs);
		bool OnStatisticsClose(const CEGUI::EventArgs& pEventArgs);

	private:

		RenderWindowPtr m_window;
		InputSystemPtr m_input;

		CEGUIResourceManager m_guiManager;
		RefPtr<CEGUI::System> m_guisystem;
		RefPtr<CEGUI::TinyXMLParser> m_xmlParser;
		RefPtr<CEGUI::DirectX9Renderer> m_guiRenderer;


		CEGUI::ButtonBase* m_startBtn;
		CEGUI::ButtonBase* m_optionsBtn;
		CEGUI::ButtonBase* m_quitBtn;
		CEGUI::ButtonBase* m_creditsBtn;

		CEGUI::FrameWindow* m_optionsWnd;
		CEGUI::ButtonBase* m_optionsOkBtn;
		CEGUI::ButtonBase* m_optionsNoBtn;
		CEGUI::Combobox* m_optionsResCombo;
		CEGUI::Combobox* m_optionsFSAACombo;
		CEGUI::Checkbox* m_optionsFullScr;
		CEGUI::Spinner* m_optionsMultiT;
		CEGUI::Checkbox* m_optionsShowStat;
		CEGUI::Checkbox* m_releaseInput;

		CEGUI::FrameWindow* m_statisticsWnd;
		CEGUI::Window*      m_statisticsFPS;
		CEGUI::Window*      m_statisticsFaces;

		CEGUI::FrameWindow* m_creditsWnd;
		CEGUI::MultiLineEditbox* m_creditsText;

		bool m_gameMenu;
	};
}

#endif
